package com.yingside.collection;

import java.util.*;

public class TestIterator {
    public static void main(String[] args) {
        /*List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbb");
        list.add("ccc");
        list.add("ddd");
        //通过集合对象获取迭代器
        Iterator<String> iterator = list.iterator();
        //循环判断迭代器有没有下一个值
        while(iterator.hasNext()){
            //获取迭代器的下一个值
            String next = iterator.next();
            System.out.println("next = " + next);
        }*/


//        Set<Teacher> sets = new HashSet<>();
//        Teacher teacher1 = new Teacher(3, "张老师");
//        Teacher teacher2 = new Teacher(1, "w老师");
//        Teacher teacher3 = new Teacher(4, "L老师");
//        Teacher teacher4 = new Teacher(2, "f老师");
//        sets.add(teacher1);
//        sets.add(teacher2);
//        sets.add(teacher3);
//        sets.add(teacher4);

//        Iterator<Teacher> iterator = sets.iterator();
//        while(iterator.hasNext()){
//            Teacher next = iterator.next();
//            System.out.println("next = " + next);
//        }


        List<Teacher> teacherList = new ArrayList<>();
        Teacher teacher1 = new Teacher(3, "张老师");
        Teacher teacher2 = new Teacher(1, "w老师");
        Teacher teacher3 = new Teacher(4, "L老师");
        Teacher teacher4 = new Teacher(2, "f老师");
        teacherList.add(teacher1);
        teacherList.add(teacher2);
        teacherList.add(teacher3);
        teacherList.add(teacher4);

        //在其他的一些语言里面，比如C#，在foreach循环中是不能改变集合的值的
        //因为会引起引用传递的一些问题
        /*for (Teacher teacher : teacherList) {
            teacher.setTeacherName("张三");
        }*/

        /*for (int i = 0; i < teacherList.size(); i++) {
            Teacher teacher = teacherList.get(i);
            //teacher.setTeacherName("张三");
            teacher = null;
        }*/

        System.out.println("=======================");
        System.out.println(teacherList);
    }
}
